using System.IO;
using Core;
using EmbeddedWebserver.Core;
using EmbeddedWebserver.Core.Handlers.Abstract;

using SolarDevices;

namespace SolarWeb
{
    class ChargeControllerLogHandler : HandlerBase
    {
        #region Non-public members

        protected override void ProcessRequestWorker(HttpContext pContext)
        {
            switch (pContext.Request.Method)
            {
                case HttpMethods.GET:
                    var targetUrl = DebugLogger.GetLogger().LogFile;
                    pContext.Response.ResponseStream = File.Open(targetUrl, FileMode.Open, FileAccess.Read);
                    pContext.Response.ContentType = "text/plain";
                    break;
                case HttpMethods.POST:
                    pContext.Response.ContentType = "application/json";
                    DebugLogger.GetLogger().ClearLog();
                    break;
            }
        }

        #endregion

        #region Constructors

        public ChargeControllerLogHandler() : base(HttpMethods.POST | HttpMethods.GET) { }

        #endregion
    }

}
